package com.jilefojing.controller;

import com.google.common.collect.Maps;
import com.jilefojing.base.BaseWeb;
import com.jilefojing.beans.data.response.base.ResponseData;
import com.jilefojing.beans.data.web.response.BannerData;
import com.jilefojing.beans.enums.PlatformEnum;
import com.jilefojing.beans.pojos.enhanced.EnhancedBanner;
import com.jilefojing.beans.vo.Pagination;
import com.jilefojing.convent.CommonConvent;
import com.jilefojing.service.IBannerService;
import com.jilefojing.util.Detect;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("banner")
public class BannerController extends BaseWeb {
    @Autowired
    private IBannerService bannerService;

    @PostMapping("list")
    public ResponseData list() {
        ResponseData responseData = new ResponseData();

        Map<String, Object> result = Maps.newHashMap();

        PlatformEnum platform = PlatformEnum.PC;
        Pagination<EnhancedBanner> enhancedBannerPagination = new Pagination<EnhancedBanner>(1, Integer.MAX_VALUE, false);
        enhancedBannerPagination = bannerService.getPaginationForActive(platform, enhancedBannerPagination, null);
        if (Detect.notEmpty(enhancedBannerPagination.getItems())) {
            List<BannerData> banners = CommonConvent.convent2BannerDatas(enhancedBannerPagination.getItems());
            result.put("items", banners);
        }
        
        responseData.setData(result);

        return responseData;
    }
}
